/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import entities.Music;
import java.util.Collection;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

/**
 *
 * @author Antoine Boulinguez et Shyn-Yuan Cheng
 */
public class SpeakkerPlaylistUtil {
    public static String getJson(Collection<Music> musics) {
        JSONObject jsonObj = new JSONObject();

        int count = 0;
        JSONArray songList = new JSONArray();
        for (Music m : musics) {
            JSONObject fileObj = new JSONObject();
            fileObj.put("src", m.getFilePath());
            fileObj.put("type", "audio/mp3");

            JSONObject configObj = new JSONObject();
            configObj.put("title", m.getTitle());
            configObj.put("cover", m.getCoverImage().replaceAll("\\\\", "\\\\\\\\"));

            JSONObject songObj = new JSONObject();
            songObj.put(count, fileObj);
            songObj.put("config", configObj);

            songList.add(songObj);
            
            count++;

        }

        jsonObj.put("playlist", songList);

        System.out.println(jsonObj.toJSONString());

        return jsonObj.toJSONString();
    }
}
